<?php
/**
 * 佣金结算-发卡人、老师、班主任
 * User: Administrator
 * Date: 2017/9/15
 * Time: 14:00
 */
namespace zhtfrontend\components\services\commission;

use yii\base\Component;
use zhtfrontend\models\datas\SettlementVoucher;

class Settlement extends Component{

    /**
     * @param $imagelist
     * @param $commission_settlement_id
     * @param $type
     * @return bool
     * 上传凭证
     */
    public static function UploadImg($imagelist,$commission_settlement_id,$type){
        $imagelist_arr = [];
        if (!empty($imagelist)) {
            $imagelist_arr = explode('#|#', $imagelist);
        }
        $transaction = \Yii::$app->db->beginTransaction();
        try {
            foreach ($imagelist_arr as $k => $v) {
                $voucher = new SettlementVoucher();
                $voucher->settlement_id = $commission_settlement_id;
                $voucher->operator_id = \Yii::$app->user->id;
                $voucher->operator = \Yii::$app->user->identity->username;
                $voucher->voucher_url = $v;
                $voucher->type = $type;
                $voucher->save(false);
            }
            $transaction->commit();
            return true;
        } catch (\Exception $e) {
            $transaction->rollBack();
            return false;
        }
    }
}